<template>
<view class="container">
 <block v-if="!jifenList">
    <view class="none">没有积分记录</view>
 </block>
 <block v-else>
  <view class="jifenContainer">
    <view class="jifenTitle">积分记录</view>
    <view class="jifenInfo" v-for="(item, index) in jifenList" :key="index">
      <block v-if="item.eventType == 0">
        <view class="jifenInfo_top">积分+{{item.eventJifen}}（累计积分：{{item.afterJifen}}）</view>
      </block>
      <block v-if="item.eventType == 1">
        <view class="jifenInfo_top">积分-{{item.eventJifen}}（累计积分：{{item.afterJifen}}）</view>
      </block>
     

      <text class="font6">{{item.eventDescription}}</text>
      <text class="jifenInfo_time">{{item.eventTime}}</text>
    </view>
  </view>
 </block>
  
</view>
</template>

<script>

export default {
  data() {
    return {
      jifenList: [],
      listPage: {
        page: 1,
        pageSize: 0,
        totalSize: 0,
        curpage: 1
      },
      setting: "",
      loginUser: ""
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getJifenList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      setting: getApp().globalData.setting
    });
    this.setData({
      loginUser: getApp().globalData.loginUser
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.jifenList = [];
    this.listPage.page = 1;
    this.getJifenList();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;

    if (that.listPage.totalSize > that.listPage.curPage * that.listPage.pageSize) {
      that.listPage.page++;
      this.getJifenList();
    }
  },
  methods: {
    /* 获取订单列表 */
    getJifenList: function () {
      var that = this;
      var getParam = {};
      getParam.page = that.listPage.page;
      var customIndex = getApp().globalData.AddClientUrl("/get_user_jifen_events.html", getParam); // wx.showLoading({
      //   title: 'loading'
      // })

      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log('-----------get_user_jifen_events--------');
          console.log(res.data);
          that.listPage.pageSize = res.data.pageSize;
          that.listPage.curPage = res.data.curPage;
          that.listPage.totalSize = res.data.totalSize;
          let dataArr = that.jifenList;
          dataArr = dataArr.concat(res.data.result);

          if (!res.data.result || res.data.result.length == 0) {
            that.setData({
              jifenList: null
            });
          } else {
            that.setData({
              jifenList: dataArr
            });
          }

          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>